﻿IF OBJECT_ID('[core].[ValidateStringParameter]') IS NOT NULL
BEGIN
	DROP PROCEDURE [core].[ValidateStringParameter]
END
GO
CREATE PROCEDURE [core].[ValidateStringParameter]
	@Value NVARCHAR(4000),
	@CanBeNull BIT = 1,
	@CanBeEmpty BIT = 1,
	@MinLength INT = 0,
	@MaxLength INT = 4000,
	@Schema SYSNAME,
	@ObjectName NVARCHAR(256),
	@EnableLogging BIT = 1,
	@VersionNumber VARCHAR(25),
	@SessionID VARCHAR(50),
	@LanguageID INT
	WITH EXECUTE AS CALLER
AS
BEGIN
	IF @CanBeNull = 0 AND @Value IS NULL
	BEGIN
		RETURN 1;
	END

	IF @CanBeEmpty = 0 AND LEN(LTRIM(RTRIM(@Value))) = 0
	BEGIN
		RETURN 2;
	END

	If LEN(@Value) < @MinLength
	BEGIN
		RETURN 3;
	END

	If LEN(@Value) > @MaxLength
	BEGIN
		RETURN 4;
	END

	RETURN 0;
END
GO
GRANT EXECUTE ON [core].[ValidateStringParameter] TO [HomeDataUser]